package com.lesserpand.rabbitmq.redis.service;

import com.lesserpand.rabbitmq.redis.service.RedissonSkillService;
import com.lesserpand.rabbitmq.redis.utils.MsService;
import org.springframework.data.redis.core.StringRedisTemplate;

public class SkillThread implements Runnable {
    private MsService service;
    private RedissonSkillService redissonSkillService;
    private StringRedisTemplate stringRedisTemplate;
    private String key;

    public SkillThread(RedissonSkillService redissonSkillService, MsService service, StringRedisTemplate stringRedisTemplate, String key) {
        this.redissonSkillService = redissonSkillService;
        this.service = service;
        this.stringRedisTemplate = stringRedisTemplate;
        this.key = key;
    }

    @Override
    public void run() {
        // 这种是利用setNX方式实现，但是自测谁有问题的。而且效率对象，redis官网推荐使用redisson实现分布式锁
        //service.seckill(redisTemplate, key);
        // 根据redisson官网文档实现分布式锁
        redissonSkillService.seckill(stringRedisTemplate);
    }
}
